﻿using IOP.Pulsar.Abstractions;
using IOP.Pulsar.ProductLineClients.TCP;
using System;
using System.Text;
using System.Threading.Tasks;

namespace StringClientTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("脉冲星测试字符串客户端");
            IClientOptions options = new DefaultClientOption();
            options.Address = "localhost";
            options.Port = 6666;
            StringTCPClient testClient = new StringTCPClient(builder =>
            {
                builder.Run(end =>
                {
                    Console.WriteLine(end.Body);
                    Console.WriteLine("请输入字符:");
                    return Task.CompletedTask;
                });
            });
            testClient.ConnectAsync(options);
            while (true)
            {
                var text = Console.ReadLine();
                text += '\n';
                string sendStr = text;
                byte[] sendBytes = Encoding.UTF8.GetBytes(sendStr);
                if (!testClient.IsConnected) break;
                testClient.Send(sendBytes);
            }
        }
    }
}
